var t = require;
var e = module;
var o = exports;
var a,
    i =
        (this && this.__extends) ||
        ((a = function (t, e) {
            return (a =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                })(t, e);
        }),
        function (t, e) {
            a(t, e);
            function o() {
                this.constructor = t;
            }
            t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o());
        }),
    n =
        (this && this.__decorate) ||
        function (t, e, o, a) {
            var i,
                n = arguments.length,
                r = n < 3 ? e : null === a ? (a = Object.getOwnPropertyDescriptor(e, o)) : a;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, a);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (i = t[s]) && (r = (n < 3 ? i(r) : n > 3 ? i(e, o, r) : i(e, o)) || r);
            return n > 3 && r && Object.defineProperty(e, o, r), r;
        };
Object.defineProperty(o, "__esModule", {value: !0});
var r = t("SplitTexture"),
    s = t("TearMoveNode"),
    c = cc._decorator,
    p = c.ccclass,
    l =
        (c.property,
        c.menu,
        (function (t) {
            i(e, t);
            function e() {
                var e = (null !== t && t.apply(this, arguments)) || this;
                e.playIndex = 0;
                return e;
            }
            e.prototype.onLoad = function () {
                EvCard.on(EvCard.ev_tearCard, this.doEffect.bind(this), this);
            };
            e.prototype.doEffect = function (t, e, o) {
                var a = this,
                    i = e.node,
                    n = this.cardNullNode(this.node.convertToNodeSpaceAR(i.convertToWorldSpaceAR(cc.Vec2.ZERO))),
                    r = n.convertToNodeSpaceAR(e.bgFont.node.convertToWorldSpaceAR(cc.Vec2.ZERO)),
                    s = n.convertToNodeSpaceAR(e.smallAnimal.node.convertToWorldSpaceAR(cc.Vec2.ZERO)),
                    c = n.convertToNodeSpaceAR(e.bigNum.node.convertToWorldSpaceAR(cc.Vec2.ZERO)),
                    p = n.convertToNodeSpaceAR(e.cardKind.node.convertToWorldSpaceAR(cc.Vec2.ZERO)),
                    l = [],
                    d = e.getCardData().kind,
                    u = e.getCardData().cardId;
                BundleManager.getSpriteTexture2D(
                    BundleManager.bn.Res,
                    "/UI/card/card_general",
                    function (t) {
                        var e = a.creatorTextureNode(r, n);
                        l.push({tex: t, com: e, isTear: !0});
                        4 == l.length && a.playData(l, n, o);
                    },
                    null
                );
                BundleManager.getSpriteTexture2D(
                    BundleManager.bn.Res,
                    "/UI/card/" + SpriteView.getCardResPathName(u, d),
                    function (t) {
                        var e = a.creatorTextureNode(c, n);
                        l.push({tex: t, com: e, isTear: !0});
                        var i = a.creatorTextureNode(s, n, 0.32);
                        l.push({tex: t, com: i, isTear: !1});
                        4 == l.length && a.playData(l, n, o);
                    },
                    null
                );
                BundleManager.getSpriteTexture2D(
                    BundleManager.bn.Res,
                    "/UI/card/" + SpriteView.getKindCoinName(d),
                    function (t) {
                        var e = a.creatorTextureNode(p, n);
                        l.push({tex: t, com: e, isTear: !1});
                        4 == l.length && a.playData(l, n, o);
                    },
                    null
                );
            };
            e.prototype.cardNullNode = function (t) {
                var e,
                    o = QLooperNode.getNode(QLooperNode.tag_tearMoveNode);
                o.parent = this.node;
                o.setPosition(t);
                null === (e = o.getComponent(s.default)) || void 0 === e || e.resetView();
                o.scale = 1;
                return o;
            };
            e.prototype.creatorTextureNode = function (t, e, o) {
                void 0 === o && (o = 1);
                var a = QLooperNode.getNode(QLooperNode.tag_splitTexture),
                    i = a.getComponent(r.default);
                a.scale = o;
                i.node.parent = e;
                i.node.setPosition(t);
                return i;
            };
            e.prototype.playData = function (t, e, o) {
                for (var a = this, i = 0; i < t.length; i++) {
                    var n = t[i];
                    n.com.resetData(n.tex);
                }
                e.runAction(
                    cc.sequence([
                        cc.spawn(
                            cc.sequence([
                                cc.delayTime(0.3),
                                cc.callFunc(function () {
                                    a.playEffect(e);
                                }, this)
                            ]),
                            cc
                                .bezierTo(0.4, [cc.v2(e.position), cc.v2(e.x / 2, e.y + 200), cc.v2(0, 100)])
                                .easing(cc.easeOut(3)),
                            cc.rotateBy(0.4, e.x > 0 ? -360 : 360),
                            cc.scaleTo(0.4, 1.5)
                        ),
                        cc.delayTime(0.2),
                        cc.callFunc(function () {
                            o && o();
                            for (var e = 0; e < t.length; e++) {
                                var a = t[e];
                                a.isTear ? a.com.playDoSplit() : a.com.downRect();
                            }
                        }, this),
                        cc.delayTime(6),
                        cc.callFunc(function () {
                            QLooperNode.putNode(e);
                        }, this)
                    ])
                );
            };
            e.prototype.playEffect = function (t) {
                var e;
                null === (e = t.getComponent(s.default)) || void 0 === e || e.play();
            };
            e.prototype.onDestroy = function () {
                EvCard.offTarget(this);
            };
            return n([p], e);
        })(cc.Component));
o.default = l;
